using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.Content.Res;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Graphics;
using Android.Net;

namespace MWC.NetcampCheckin
{
    [Activity(Label = "NetcampNextMeeting")]
    public class NetcampNextMeeting : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            try
            {
                base.OnCreate(bundle);
                SetContentView(Resource.Layout.NetcampNextMeeting);

                List<TextView> listBold = new List<TextView>();
                listBold.Add(FindViewById<TextView>(Resource.Id.firstParenthasesOfTitle));
                listBold.Add(FindViewById<TextView>(Resource.Id.secondParanthasesOfTitle));
                listBold.Add(FindViewById<TextView>(Resource.Id.boldTextOfSubtitle));
                listBold.Add(FindViewById<TextView>(Resource.Id.boldTextOfTitle));
                setFont("fonts/texgyreheros-regular-webfont.ttf", listBold, TypefaceStyle.Bold);


                List<TextView> listNormal = new List<TextView>();
                listNormal.Add(FindViewById<TextView>(Resource.Id.normalTextOfTitle));
                listNormal.Add(FindViewById<TextView>(Resource.Id.normalTextOfSubtitle));
                listNormal.Add(FindViewById<TextView>(Resource.Id.nextMeeting));
                listNormal.Add(FindViewById<TextView>(Resource.Id.date));
                listNormal.Add(FindViewById<TextView>(Resource.Id.Ups));
                setFont("fonts/texgyreheros-regular-webfont.ttf", listNormal, TypefaceStyle.Normal);

                Button bIwant = FindViewById<Button>(Resource.Id.Iwant);

                bIwant.Click += delegate
                {
                    var email = new Intent(Intent.ActionView);
                    email.SetData(Uri.Parse("mailto:kontakt@netcamp.pl"));
                    try {
                        StartActivity(email);
                    }
                    catch(System.Exception e)
                    {
                        MWCApp.LogDebug(e.Message);
                    }
                };

                Button bLetMeKnow = FindViewById<Button>(Resource.Id.LetMeKnow);

                bLetMeKnow.Click += (s, e) =>
                    {
                        NetcampWebProxy.WebProxy proxy = new NetcampWebProxy.WebProxy();
                        proxy.Proxy = null;

                        var prefs = GetSharedPreferences("NetcampApp", 0);
                        var email = prefs.GetString("Email", "");

                        proxy.SaveEmailToRemindAsync(email);

                        NetcampAlerts.WeWillSendEmail(this);
                    };
                //listNormal[3].Text += b_Iwant.Text;
            }
            catch (System.Exception e)
            {
                MWCApp.LogDebug(e);
                NetcampAlerts.UnknownError(this);
            }
        }

        private int ConvertPixelsToDp(float pixelValue)
        {
            var dp = (int)((pixelValue) / Resources.DisplayMetrics.Density);
            return dp;
        }
        // 1 - sciezka do czcionki, 2 - tablica, 3 - Typ:Bold,Italic,Normal,BoldItalic
        private void setFont(string path, List<TextView> tTV, TypefaceStyle Type)
        {
            AssetManager mgr;
            mgr = Assets;
            Typeface font = Typeface.CreateFromAsset(mgr, path);
            for (int i = 0; i < tTV.Count; i++)
            {
                tTV[i].SetTypeface(font, Type);
            }

        }
    }
}
